package com.ruoyi.web.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.admin.domain.TdmCmsp;
import com.ruoyi.web.admin.service.ITdmCmspService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * CMSPController
 * 
 * @author ly
 * @date 2022-03-10
 */
@RestController
@RequestMapping("/admin/cmsp")
public class TdmCmspController extends BaseController
{
    @Autowired
    private ITdmCmspService tdmCmspService;

    /**
     * 查询CMSP列表
     */
    @PreAuthorize("@ss.hasPermi('admin:cmsp:list')")
    @GetMapping("/list")
    public TableDataInfo list(TdmCmsp tdmCmsp)
    {
        startPage();
        List<TdmCmsp> list = tdmCmspService.selectTdmCmspList(tdmCmsp);
        return getDataTable(list);
    }

    /**
     * 导出CMSP列表
     */
    @PreAuthorize("@ss.hasPermi('admin:cmsp:export')")
    @Log(title = "CMSP", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdmCmsp tdmCmsp)
    {
        List<TdmCmsp> list = tdmCmspService.selectTdmCmspList(tdmCmsp);
        ExcelUtil<TdmCmsp> util = new ExcelUtil<TdmCmsp>(TdmCmsp.class);
        util.exportExcel(response, list, "CMSP数据");
    }

    /**
     * 获取CMSP详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:cmsp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tdmCmspService.selectTdmCmspById(id));
    }

    /**
     * 新增CMSP
     */
    @PreAuthorize("@ss.hasPermi('admin:cmsp:add')")
    @Log(title = "CMSP", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdmCmsp tdmCmsp)
    {
        return toAjax(tdmCmspService.insertTdmCmsp(tdmCmsp));
    }

    /**
     * 修改CMSP
     */
    @PreAuthorize("@ss.hasPermi('admin:cmsp:edit')")
    @Log(title = "CMSP", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdmCmsp tdmCmsp)
    {
        return toAjax(tdmCmspService.updateTdmCmsp(tdmCmsp));
    }

    /**
     * 删除CMSP
     */
    @PreAuthorize("@ss.hasPermi('admin:cmsp:remove')")
    @Log(title = "CMSP", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tdmCmspService.deleteTdmCmspByIds(ids));
    }
}
